import * as Local from "./drivers/local";
import * as Cos from "./drivers/cos";
import * as Oss from "./drivers/oss";
import store from "../../../store";
import { computed } from "vue";

const work_ai_config = computed(() => {
  return store?.state?.shotstack?.work_ai_config || {};
});

export function createUploader(driver) {
  if (driver === "cos") {
    return Cos;
  } else if (driver == "alionline") {
    return Oss;
  }

  return Local;
}

export async function upload(file, config = {}, atherConfige={}) {
  let uploader;

  if (
    work_ai_config.value?.shotstack_driver == "alionline" ||
    work_ai_config.value?.upload_driver == "oss"
  ) {
    uploader = createUploader("alionline");
  } else if (work_ai_config.value?.upload_driver == "cos") {
    uploader = createUploader(work_ai_config.value.upload_driver);
  } else {
    uploader = createUploader();
  }

  return uploader.upload(file, config, atherConfige);
}
